<template>
    <div class="app-container calendar-list-container">
    <el-row class="panel-group" :gutter="40">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">订单总金额</div>
            <count-to class="card-panel-num" :startVal="0" :endVal="dataCount.amt" :duration="3200"></count-to>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">订单总手续费</div>
            <count-to class="card-panel-num" :startVal="0" :endVal="dataCount.fee" :duration="3200"></count-to>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-shoppingCard">
            <svg-icon icon-class="shoppingCard" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">成功订单数</div>
            <count-to class="card-panel-num" :startVal="0" :endVal="dataCount.count" :duration="3600"></count-to>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">今日成功订单金额</div>
            <count-to class="card-panel-num" :startVal="0" :endVal="dataCount.today" :duration="3200"></count-to>
          </div>
        </div>
      </el-col>
  </el-row>

        <!-- 查询和其他操作 -->
        <div class="filter-container">
            <el-input clearable v-if="merchantId == null"  style="width: 200px;" placeholder="商户号" v-model="listQuery.merchantId"></el-input>
            <el-input clearable  style="width: 200px;" placeholder="订单号" v-model="listQuery.payOrderNo"></el-input>
            <el-select v-model="listQuery.orderStatus" placeholder="订单状态" clearable="">
              <el-option label="支付成功" value="00"> </el-option>
              <el-option label="支付失败" value="01"> </el-option>
              <el-option label="待支付" value="02"> </el-option>
              <el-option label="支付中" value="03"> </el-option>
              <el-option label="作废" value="04"> </el-option>
            </el-select>
            <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查询</el-button>
        </div> 
        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>
            <el-table-column align="center" min-width="120px" label="平台编号" prop="platformId"></el-table-column>
            <el-table-column align="center" min-width="120px" label="商户账号" prop="merchantId"></el-table-column>
            <el-table-column align="center" min-width="120px" label="商户名称" prop="merchantName"></el-table-column>
            <el-table-column align="center" min-width="130px" label="付款人支付宝昵称" prop="nickname"></el-table-column>
            <el-table-column align="center" min-width="130px" label="付款人支付宝账号" prop="payAccount"></el-table-column>
            <el-table-column align="center" min-width="130px" label="付款人支付宝姓名" prop="realname"></el-table-column>
            <el-table-column align="center" min-width="130px" label="设备id" prop="deviceId"></el-table-column>
            <el-table-column align="center" min-width="120px" label="订单号" prop="payOrderNo"></el-table-column>
            <el-table-column align="center" min-width="120px" label="客户账号" prop="customerId"></el-table-column>
            <el-table-column align="center" min-width="110px" label="交易时间" prop="payTime"></el-table-column>
            <el-table-column align="center" min-width="80px" label="订单金额" prop="orderAmt"></el-table-column>
            <el-table-column align="center" min-width="80px" label="实际交易金额" prop="payAmt"></el-table-column>
            <el-table-column align="center" min-width="100px" label="订单描述" prop="body"></el-table-column>
            <el-table-column align="center" min-width="80px" label="交易类型">
                <template slot-scope="scope">
                    <span v-if="scope.row.payCode == '1'">支付</span>
                    <span v-if="scope.row.payCode == '2'">充值</span>
                </template>
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="支付类型">
                <template slot-scope="scope">
                    <span v-if="scope.row.payStyle == '0'">动态</span>
                    <span v-if="scope.row.payStyle == '1'">静态</span>
                </template>
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="支付方式">
                <template slot-scope="scope">
                    <span v-if="scope.row.payMethod == '1'">支付宝</span>
                    <span v-if="scope.row.payMethod == '2'">微信</span>
                </template>
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.orderStatus == '00'">支付成功</span>
                    <span v-if="scope.row.orderStatus == '01'">支付失败</span>
                    <span v-if="scope.row.orderStatus == '02'">待支付</span>
                    <span v-if="scope.row.orderStatus == '03'">支付中</span>
                    <span v-if="scope.row.orderStatus == '04'">作废</span>
                </template>
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="通知商户状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.callbackStatus == '00'">已通知</span>
                    <span v-if="scope.row.callbackStatus == '01'">未通知</span>
                </template>
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="已退款金额" prop="refundedAmt"></el-table-column>
            <el-table-column align="center" label="操作" width="400" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button  type="primary" size="small" v-if="scope.row.orderStatus != '00'" @click="handleUptStatus(scope.row)">更新状态</el-button>
                    <el-button  type="primary" v-if="scope.row.callbackStatus == '01'" size="small" @click="handleNotice(scope.row)">通知第三方</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pagination-container" v-show="!listLoading">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
                :page-sizes="[10,20,30,50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>

        <!-- 通知弹框 -->
        <el-dialog title="通知" :visible.sync="dialogNotice">
            <el-form :rules="rule" ref="noticeForm" :model="noticeForm" status-icon label-position="left" label-width="150px" style='width: 400px; margin-left:50px;'>
                <el-form-item label="金额: " prop="payAmt">
                    <el-input v-model="noticeForm.payAmt"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel('noticeForm')">取消</el-button>
                <el-button type="primary" @click="doNotice('noticeForm')">确定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<style>

</style>

<script>
import { orderList, dataCount, uptStatus, noticeAct } from '@/api/order/payOrder'
import waves from '@/directive/waves' // 水波纹指令
import { mapGetters } from 'vuex'
import CountTo from 'vue-count-to'
export default {
  components: {
    CountTo
  },
  directives: { waves },
  data: function() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        merchantId: '',
        platformId: '',
        payOrderNo: '',
        orderStatus: ''
      },
      noticeForm: {
        payAmt: '',
        orderNo: '',
        platformId: ''
      },
      rule: {
        payAmt: [
          {
            pattern: /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/,
            message: '输入格式错误，请重新输入!'
          }
        ]
      },
      channel_btn_info: false,
      channel_btn_add: false,
      channel_btn_update: false,
      channel_btn_delete: false,
      channel_btn_interface: false,
      list: [],
      total: 0,
      dataCount: {
        amt: 0,
        fee: 0,
        count: 0,
        today: 0
      },
      listLoading: false,
      dialogNotice: false
    }
  },
  computed: {
    ...mapGetters([
      'elements',
      'name',
      'merchantId',
      'platformId'
    ])
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },

    getDataCount() {
      var str = {}
      str.platformId = this.platformId
      str.merchantId = this.merchantId
      dataCount(str).then(response => {
        if (response.data) {
          var ddd = response.data
          if (ddd.amt) {
            this.dataCount.amt = ddd.amt
          }
          if (ddd.fee) {
            this.dataCount.fee = ddd.fee
          }
          if (ddd.count) {
            this.dataCount.count = ddd.count
          }
          if (ddd.today) {
            this.dataCount.today = ddd.today
          }
        }
      })
    },
    handleUptStatus(row) {
      row.orderStatus = '00'
      this.$confirm('请确认, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        uptStatus(row).then(response => {
          if (response.data.code === '0000') {
            this.$notify({
              title: '成功',
              message: '操作成功',
              type: 'success',
              duration: 2000
            })
            this.getList()
          }
        })
      })
    },
    handleNotice(row) {
      this.noticeForm.orderNo = row.payOrderNo
      this.noticeForm.platformId = row.platformId
      this.noticeForm.payAmt = ''
      this.dialogNotice = true
    },

    cancel() {
      this.dialogNotice = false
    },

    doNotice() {
      noticeAct(this.noticeForm).then(response => {
        if (response.data.code === '0000') {
          this.$notify({
            title: '成功',
            message: '操作成功',
            type: 'success',
            duration: 2000
          })
          this.getList()
        }
      })
    },
    getList() {
      this.listLoading = true
      this.listQuery.platformId = this.platformId
      this.listQuery.merchantId = this.merchantId
      orderList(this.listQuery)
        .then(response => {
          console.log(response)
          this.list = response.data.rows
          this.total = response.data.total
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    }
  },
  created() {
    this.getList()
    this.getDataCount()
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.panel-group {
  margin-top: 18px;
  .card-panel-col{
    margin-bottom: 32px;
  }
  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }
      .icon-people {
         background: #40c9c6;
      }
      .icon-message {
        background: #36a3f7;
      }
      .icon-money {
        background: #f4516c;
      }
      .icon-shoppingCard {
        background: #34bfa3
      }
    }
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shoppingCard {
      color: #34bfa3
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin-top: 26px;
      margin-left: 0px;
      margin-right: 26px;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>

